package com.dg.cuckoo.admin.action.basicInformation;

import com.dg.cuckoo.admin.service.OrganizationService;
import com.dg.cuckoo.admin.service.ProjectInfoServer;
import com.dg.cuckoo.core.BaseController;
import com.dg.cuckoo.core.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 基本资料-组织架构
 */
@RestController
@RequestMapping("/basicInformation/organization")
public class Organization extends BaseController {

    @Autowired
    private OrganizationService service;
    @Autowired
    private ProjectInfoServer projectInfoServer;

    /**
     * 保存
     * @param userId 用户名称id
     * @param units  多选单位
     * @return
     */
    @PostMapping("save/id")
    public JsonResult<Void> save(@PathVariable String userId, List<String> units) {
        service.save(userId, units);
        return new JsonResult<>(OK);
    }

    /**
     * 组织架构页面显示
     */
    @PostMapping("view")
    public JsonResult<String> view(){
        String data = service.view();
        return new JsonResult<>(OK,data);
    }

//    /**
//     * 建设单位点击显示二级标签
//     * @param unit 名称
//     * @return
//     */
//    @PostMapping("clickUnitTreeInfo")
//    public JsonResult<String> clickUnitTreeInfo(String unit){
//        String data = projectInfoServer.clickUnitTreeInfo(unit);
//        return new JsonResult<>(OK,data);
//    }

    /**
     * 点击用户显示单位
     */
    @PostMapping("openUnitByUser")
    public JsonResult<List<String>> openUnitByUser(String userId){
        List<String> date = service.openUnitByUser(userId);
        return new JsonResult<>(OK,date);
    }
}
